package com.jwthhealth_pub.old.subscribe.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.old.common.ImageLoader;
import com.jwthhealth_pub.old.subscribe.SubscribeActivity;
import com.jwthhealth_pub.old.subscribe.model.SubscribeIndex;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 最近门店
 * Created by Administrator on 2017/7/13.
 */

public class CloseShopAdapter extends RecyclerView.Adapter {

    private SubscribeActivity subscribeActivity;
    private List<SubscribeIndex.DataBean> data;
    private int mChoosePos = -1;

    public CloseShopAdapter(SubscribeActivity subscribeActivity, List<SubscribeIndex.DataBean> data) {
        this.subscribeActivity = subscribeActivity;
        this.data = data;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(View.inflate(subscribeActivity, R.layout.item_close_shop, null));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
        ViewHolder vh = (ViewHolder) holder;

        final SubscribeIndex.DataBean dataBean = data.get(position);

        ImageLoader.picasso(dataBean.getPic(), vh.itemImg);
        vh.itemShopName.setText(dataBean.getName());
        vh.itemShopIndex.setText("附近门店" + (position+1) + "");
        vh.itemShopPhone.setText("电话:" + dataBean.getPhone() + "");
        vh.itemShopAddress.setText("地址:" + dataBean.getPos() + "");

//        if(position == mChoosePos)
//            vh.cliakLaout.setBackgroundColor(ContextCompat.getColor(subscribeActivity,R.color.dividual_gray));
//        else
//            vh.cliakLaout.setBackgroundColor(ContextCompat.getColor(subscribeActivity,R.color.white));

        vh.cliakLaout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //todo 选择门店, 更新页面
//                ((SubscribeContect.presenter)subscribeActivity.getPresenter()).choiceShop("");
                subscribeActivity.choiceShop(dataBean);
                mChoosePos = position;
            }
        });
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.item_img)
        ImageView itemImg;
        @BindView(R.id.item_shop_name)
        TextView itemShopName;
        @BindView(R.id.item_shop_index)
        TextView itemShopIndex;
        @BindView(R.id.item_shop_phone)
        TextView itemShopPhone;
        @BindView(R.id.item_shop_address)
        TextView itemShopAddress;
        @BindView(R.id.item_shop_click_layout)
        RelativeLayout cliakLaout;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }
}
